var table;
layui.use('table', function(){
    table = layui.table
        ,form = layui.form;

    table.render({
        elem: '#test'
        ,url:'/user/JsonUserRankList'
        ,cellMinWidth: 80
        ,cols: [[
            {type:'numbers'}
            ,{type: 'checkbox'}
            ,{field:'rankid', title:'ID'}
            ,{field:'rankname', title:'等级名称'}
            ,{field:'recommend', title:'直推奖'}
            ,{field:'commission', title: '店主节省'}
            ,{field:'sort', title: '排序'}
            ,{field:'rankid', title:'编辑', minWidth:180, templet: '#barDemo', unresize: true}
        ]]
        ,page: true
        ,limit:10
        ,id: 'testReload'
    });

    //监听表格复选框选择
    table.on('checkbox(demo)', function(obj){
        console.log(obj)
    });
});


function WinOpenAdd() {
    layer.open({
        type: 2
        , title: '添加会员等级'
        , content: '/user/getUserRankAdd'
        , area: ['420px', '420px']
        , btn: ['确定', '取消']
        , yes: function (index, layero) {
            debugger;
            var body = layer.getChildFrame('body', index); //得到iframe页的body内容
            var rankname = body.find("#rankname").val();
            var recommend = body.find("#recommend").val();
            var commission = body.find("#commission").val();
            var sort = body.find("#sort").val();

            var addUrl="/user/addUserRank?rankname="+rankname+"&recommend="+recommend+"&commission="+commission+"&sort="+sort;
            var htmlobj=$.ajax({url:addUrl,async:false});
            //数据刷新
            var demoReload = $('#demoReload');
            //执行重载
            table.reload('testReload', {
            });

            layer.close(index); //关闭弹层
        }
    });
}

function WinOpenEdit(rankid) {
    layer.open({
        type: 2
        , title: '编辑会员等级'
        , content: '/user/getUserRankEdit?rankid='+rankid
        , area: ['420px', '420px']
        , btn: ['确定', '取消']
        , yes: function (index, layero) {
            debugger;
            var body = layer.getChildFrame('body', index); //得到iframe页的body内容
            var rankname = body.find("#rankname").val();
            var recommend = body.find("#recommend").val();
            var commission = body.find("#commission").val();
            var sort = body.find("#sort").val();

            var addUrl="/user/editUserRank?rankid="+rankid+"&rankname="+rankname+"&recommend="+recommend+"&commission="+commission+"&sort="+sort;
            var htmlobj=$.ajax({url:addUrl,async:false});
            //数据刷新
            var demoReload = $('#demoReload');
            //执行重载
            table.reload('testReload', {
            });

            layer.close(index); //关闭弹层
        }
    });
}

function WinOpenShow(rankid) {
    layer.open({
        type: 2
        , title: '查看会员等级'
        , content: '/user/getUserRankShow?rankid='+rankid
        , area: ['420px', '420px']
    });
}

function DelData(rankid) {
    layer.open({
        title: '消息'
        , content: '是否确定删除编号为：'+rankid+' 的数据!!'
        , btn: '确定删除'
        , yes: function () {
            var delUrl = "/user/delUserRank?rankId=" + rankid;
            //alert(curr);
            var htmlobj = $.ajax({url: delUrl, async: false});
            //alert(htmlobj.responseText);
            //数据刷新
            var demoReload = $('#demoReload');
            //执行重载
            table.reload('testReload', {
            });
            layer.closeAll();
        }
    });
/*
     if(confirm("是否确定删除编号为："+rankid+" 的数据!!"))
    {
        var delUrl = "/user/delUserRank?rankId=" + rankid;
        //alert(curr);
        var htmlobj = $.ajax({url: delUrl, async: false});
        //alert(htmlobj.responseText);
        //数据刷新
        var demoReload = $('#demoReload');
        //执行重载
        table.reload('testReload', {
            page: {
                //curr: 1 //重新从第 1 页开始
            }
            , where: {
                key: {
                    id: demoReload.val()
                }
            }
        });
    }
    */
}